package com.four.user.config;

import org.apache.http.HttpResponse;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class MsgUtil {



    public static String sendMsg(String phone){
        Random random = new Random();
        int a=4;
        String yzm = "";
        for(int i = 0;i<a;i++){

            yzm+=random.nextInt(10);
        }

        System.out.println("验证码是："+yzm);

        String host = "http://dingxin.market.alicloudapi.com";
        String path = "/dx/sendSms";
        String method = "POST";
        String appcode = "2b4dc3b94d7f43edb049e5cb00a6d5ef";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);
        querys.put("param", "code:"+yzm);
        querys.put("tpl_id", "TP1711063");
        Map<String, String> bodys = new HashMap<String, String>();


        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
            System.out.println(response.toString());
            //获取response的body
        } catch (Exception e) {
            e.printStackTrace();
        }

        return yzm;
    }
}
